/*
 * Copyright (C) 2008 CERNET Network Center 
 * dvping/dvmcast/hdvping/hdvmcast series 
 * 
 * Design and coding: 
 *  	Xing Li <xing@cernet.edu.cn> 
 *	Congxiao Bao <congxiao@cernet.edu.cn>
 * 	Jinpeng Jiang <jjp02@mails.tsinghua.edu.cn>
 * 
 * Contributions:
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 */


#include "SelfReflectDVDestination.h"

SelfReflectDVDestination::SelfReflectDVDestination(sa_family_t sa_family, in_port_t dst_port, int32_t log_period/* = 0*/)
{
	this->dst_port = dst_port;
	sock = Socket::CreateUdpSender(sa_family);
}
SelfReflectDVDestination::~SelfReflectDVDestination()
{
	sock.Close();
}

bool SelfReflectDVDestination::Init()
{
	return true;
}

bool SelfReflectDVDestination::DealPacket(char* packet, int length, const IPEndPoint& ep)
{
	if(!ep.Address().IsValid())
		return false;
	if(packet == NULL || length < 4)
		return false;
	return sock.SendTo(packet, length, IPEndPoint(ep.Address(), dst_port)) == length;
}

